package com.tledu.service.impl;

import com.tledu.mapper.AccountMapper;
import com.tledu.service.IAccountService;
import com.tledu.service.ILogService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;
import java.math.BigDecimal;

/**
 * @author cyrus
 */
@Service
@AllArgsConstructor
public class AccountServiceImpl implements IAccountService {

    private AccountMapper accountMapper;

    private final ILogService logService;

    @Override
    @Transactional(rollbackFor = Exception.class,noRollbackFor = IOException.class,isolation = Isolation.REPEATABLE_READ)
    public void transfer(String from, String to, BigDecimal money) throws IOException {
        logService.addLog(from+"转给了"+to+money+"块钱");
        accountMapper.outMoney(from, money);
        int i = 1 / 0;
//        throw new IOException("IOException");
//        throw new RuntimeException("RuntimeException");
        accountMapper.inMoney(to,money);
    }
}
